import AbstractField from '@/components/hhd/design/FormDesigner/field/comps/AbstractField';
import {createDefaultFieldElement} from '@/utils/FormDesignUtils';
import {createField} from '@/components/hhd/design/FormDesigner/types';
import {guid} from '@/utils';
import $ from 'jquery';

export default class Text extends AbstractField {
    getFieldComponentTitle() {
        return '文本域';
    }

    getFieldComponentName() {
        return 'text';
    }

    getDefaultConfig() {
        return new Promise((resolve) => {
            let field = createField();
            field.id = guid();
            field.component = 'text'
            field.fieldName = '文本域'
            field.label = '文本域'
            field.placeholder = '请输入文本'
            resolve(field);
        });
    }

    checkField(field) {
        return super.checkField(field);
    }

    createFieldElement() {
        return new Promise((resolve) => {
            resolve(this.createDefaultFieldElement());
        })
    }

    setFieldTitle(el, fieldConfig) {
        $(el).find('span[data-role=field-title]').html(fieldConfig.label);
    }

    createDefaultFieldElement() {
        let res = createDefaultFieldElement();
        $(res).addClass('field-text-area')
        res.innerHTML = '<span data-role="field-title">文本域</span>'
        return res;
    }
};
